package common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static weeny.util.io.IOUtil.SLASH;
import weeny.recycle.Control;

@SuppressWarnings("deprecation")
public class Common {
	public static String[] NAMES = { "Microsoft", "Merck", "Sony", "Verizon",
			"NYSE", "China" };
	private static final String TEXT_DIR = Control.projectFolder() + ".."
			+ SLASH + "textProcessing" + SLASH + "data"
			+ SLASH;
	private static final String DATA_DIR = "data" + SLASH;

	public static Pattern fileNamePattern = Pattern.compile(".*/([0-9]+)_([0-9]+)\\.txt.*");

	public static int dateInFileName(String name) {
		Matcher m = fileNamePattern.matcher(name);
		if (m.matches()) {
			return Integer.parseInt(m.group(1));
		} else {
			throw new IllegalArgumentException("wrong name: " + name);
		}
	}

	public static int idInFileName(String name) {
		Matcher m = fileNamePattern.matcher(name);
		if (m.matches()) {
			return Integer.parseInt(m.group(2));
		} else {
			throw new IllegalArgumentException("wrong name: " + name);
		}
	}

	public static String stockFolder(String companyName) {
		return DATA_DIR + companyName + SLASH + "stock" + SLASH;
	}

	public static String docFolder(String companyName) {
		return TEXT_DIR + companyName + SLASH + "docs" + SLASH;
	}

	public static String wheelFolder(String companyName) {
		return DATA_DIR + companyName + SLASH + "wheel" + SLASH;
	}

	public static String wheelFolder(int idx) {
		return wheelFolder(NAMES[idx]);
	}

	public static String docFolder(int idx) {
		return docFolder(NAMES[idx]);
	}

	public static String originalFile(String companyName) {
		return TEXT_DIR + companyName + SLASH + companyName;
	}

	public static String originalFile(int idx) {
		return originalFile(NAMES[idx]);
	}

	public static String MICROSOFT = NAMES[0];
	public static String MERCK = NAMES[1];
	public static String SONY = NAMES[2];
	public static String VERIZON = NAMES[3];
	public static String NYSE = NAMES[4];
	public static String CHINA = NAMES[5];
}